<?php
namespace Admin\Controller;
use Think\Controller;
class AdmininfoController extends BaseController {
    public function index(){
    	if(IS_POST){
    	if ($_FILES ['admin_pic'] ['name'] != null)
         	$data ["admin_pic"] = $this->upload ( $_FILES ['admin_pic'] );
    	$data["admin_id"]=$_POST["admin_id"];
    	$data["admin_name"]=$_POST["admin_name"];
    	if ($_POST["admin_pwd"]  != null)
    	$data["admin_pwd"]=md5($_POST["admin_pwd"]);
    	$data["admin_truename"]=$_POST["admin_truename"];
    	$data["admin_email"]=$_POST["admin_email"];
    	$data["admin_nickname"]=$_POST["admin_nickname"];
    		
    	$result=M("admin")->save($data);
    	if($result){
    		session('admin',$data['admin_name']);
				session('nickname',$data['admin_nickname']);  
				session('user',$data);  
    	$this->success("修改成功");
    	}
    	else
    	$this->error("修改失败");
    	}
    	else{
    	$data=M("admin")->where("admin_id=1")->find();
    	$this->assign("info",$data);
    	$this->display();
    	}
    }
    /**
	 * 上传
	 * @param unknown_type $filename
	 * @return string
	 */
	public function upload($filename) {
		$upload = new \Think\Upload (); // 实例化上传类
		$upload->maxSize = 3145728; // 设置附件上传大小
		$upload->exts = array ('jpg', 'gif', 'png', 'jpeg' ); // 设置附件上传类型
		$upload->rootPath = './Public/Upload/'; // 设置附件上传根目录
		$upload->savePath = '';
		// 上传单个文件 
		$info = $upload->uploadOne ( $filename );
		if (! $info) { // 上传错误提示错误信息
			$this->error ( $upload->getError () );
			exit ();
		} else { // 上传成功 获取上传文件信息
			return $info ['savepath'] . $info ['savename'];
		}
	}
	
}